<template>
  <div id="app" v-bind:style="appDivStyle">
      <div class="context" ref="context">
           <div class="queryBox" ref="queryBox">
                <el-form :model="formQueryCondition"
                         ref="form" size="mini">
                    <!--查询条件-->
                    <el-row>
                        <el-col :span="5">
                            <!--剧集编号-->
                            <el-form-item :label="$t('AssetIssuance.queryLabel.subAssetCode')"
                            :label-width="queryformLabelWidth">
                                <el-input v-model.trim="formQueryCondition.code.val" class="queryItemStyle" clearable
                                        :placeholder="$t('AssetIssuance.queryLabel.placeholderSubAssetCode')"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5" :offset="1">
                            <!--剧集名称-->
                            <el-form-item :label="$t('AssetIssuance.queryLabel.subAssetName')"   :label-width="queryformLabelWidth">
                                <el-input v-model.trim="formQueryCondition.name.val" class="queryItemStyle" clearable
                                        :placeholder="$t('AssetIssuance.queryLabel.placeholderSubAssetName')">
                                </el-input>
                            </el-form-item>
                        </el-col>
                            <!--导演
                            <el-form-item :label="$t('AssetIssuance.queryLabel.director')"   :label-width="queryformLabelWidth">
                                <el-input v-model.trim="formQueryCondition.director.val" class="queryItemStyle" clearable
                                        :placeholder="$t('AssetIssuance.label.placeholder')+$t('AssetIssuance.queryLabel.director')">
                                </el-input>
                            </el-form-item>
                            -->
                            <!--演员
                            <el-form-item :label="$t('AssetIssuance.queryLabel.actor')"   :label-width="queryformLabelWidth">
                                <el-input v-model.trim="formQueryCondition.actor.val" class="queryItemStyle" clearable
                                        :placeholder="$t('AssetIssuance.label.placeholder')+$t('AssetIssuance.queryLabel.actor')">
                                </el-input>
                            </el-form-item>
                            -->
                        <el-col :span="5" :offset="1">
                            <!--创建时间-->
                            <el-form-item :label="$t('AssetIssuance.queryLabel.createTime')"  :label-width="queryformLabelWidth">
                                <el-date-picker v-model="formQueryCondition.createTimeStart.val" class="queryItemStyle"
                                                type="date" :placeholder="$t('AssetIssuance.label.pleaseSelectTime')">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5" :offset="1">
                            <!-- 至 -->
                            <el-form-item :label="$t('AssetIssuance.label.to')"  :label-width="queryformLabelWidth">
                                <el-date-picker v-model="formQueryCondition.createTimeEnd.val" class="queryItemStyle"
                                                value-format="yyyy-MM-dd 23:59:59"
                                                type="date" :placeholder="$t('AssetIssuance.label.pleaseSelectTime')"></el-date-picker>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="5">
                            <!--更新日期-->
                            <el-form-item :label="$t('AssetIssuance.queryLabel.lastUpdateTime')"  :label-width="queryformLabelWidth">
                                <el-date-picker v-model="formQueryCondition.lastUpdateTimeStart.val" class="queryItemStyle"
                                                type="date" :placeholder="$t('AssetIssuance.label.pleaseSelectTime')"></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5" :offset="1">
                            <!-- 至 -->
                            <el-form-item :label="$t('AssetIssuance.label.to')"  :label-width="queryformLabelWidth">
                                <el-date-picker v-model="formQueryCondition.lastUpdateTimeEnd.val" class="queryItemStyle"
                                                value-format="yyyy-MM-dd 23:59:59"
                                            type="date" :placeholder="$t('AssetIssuance.label.pleaseSelectTime')"></el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5" :offset="1">
                            <!--资产来源-->
                            <el-form-item :label="$t('AssetIssuance.queryLabel.source')"  :label-width="queryformLabelWidth">
                                <el-select v-model="formQueryCondition.source.val" class="queryItemStyle">
                                    <el-option :label="$t('ParentAssetIssuance.label.all')" value=""></el-option>
                                    <el-option :value="item.keyId" :key="item.keyId" :label="item.speAreaName" v-for="item in assetSourceData"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="5" :offset="1">
                            <!--下发状态-->
                            <el-form-item :label="$t('ParentAssetIssuance.queryLabel.ParentAssetIssuance.status')"  :label-width="queryformLabelWidth">
                                <el-select v-model="formQueryCondition.status.val" class="queryItemStyle">
                                    <el-option :label="$t('ParentAssetIssuance.label.all')" value=""></el-option>
                                    <el-option :value="item.valueCode" :key="item.valueCode" :label="item.valueText" v-for="item in sendtoStateData"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                    </el-row>

                    <!--列表上面的按钮-->
                    <el-row>
                        <el-col :span="24">
                            <div style="text-align:right">
                                <!--返回-->
                                <el-form-item>
                                    <el-button type="primary" @click="back" icon="el-icon-back">{{ $t('btnText.backBtnText') }}</el-button>
                                <!-- </el-form-item> -->
                                <!--批量下发-->
                                <!-- <el-form-item> -->
                                    <el-button v-permission="{menuCode: menuCode, resourceCode: 'batchSendSubBtnText'}" :disabled="curRootAssets.sendtoStateFlag!='DownAlready'"
                                    type="primary" @click="onBatchSend('batchSendSubBtnText')">{{ $t('btnText.batchSend') }}</el-button>
                                <!-- </el-form-item> -->
                                <!--导出
                                <el-form-item>
                                    <el-button type="primary" @click="onExport" icon="el-icon-download" :loading="loading">{{ $t('AssetIssuance.btnText.exportBtnText') }}</el-button>
                                </el-form-item>
                                -->
                                <!--重置-->
                                <!-- <el-form-item> -->
                                    <el-button v-permission="{menuCode: menuCode, resourceCode: 'resetSubBtnText'}"
                                    type="primary" @click="onReset('form')">{{ $t('AssetIssuance.btnText.resetBtnText') }}</el-button>
                                <!-- </el-form-item> -->
                                <!--查询-->
                                <!-- <el-form-item> -->
                                    <el-button v-permission="{menuCode: menuCode, resourceCode: 'querySubBtnText'}"
                                    type="primary" @click="onQuery('querySubBtnText')" icon="el-icon-search" :loading="loading">{{ $t('AssetIssuance.btnText.queryBtnText') }}</el-button>
                                </el-form-item>
                            </div>
                        </el-col>
                    </el-row>
                </el-form>
            </div>
            <!--列表-->
            <div class="dataBox" ref="dataBox">

                <el-table v-if="isInit" ref="singleTable"
                            :data="tableData"
                            :height="tableHeight"
                            @sort-change="sortChange"
                            @selection-change="changeBox"
                            v-loading="loading" size="mini"
                            style="width: 100%;" stripe=stripe border=border>
                    <!--序号-->
                    <!-- <el-table-column type="index"  width="50" fixed="left"
                                        :label="$t('table.xh')" align="center">
                    </el-table-column> -->
                    <!--复选框-->
                    <el-table-column type="selection" align="center" width="35" fixed="left" :selectable='checkboxInit'>
                    </el-table-column>
                    <!--操作-->
                    <el-table-column :label="$t('table.op')" fixed="left" min-width="180">
                        <template slot-scope="scope">
                            <!--资产详情-->
                            <!-- <el-button size="gv" icon="el-icon-tickets" :loading="loading"
                             @click="clickDetails(scope.$index, scope.row)"
                                        >{{ $t('AssetIssuance.btnText.detailsBtnText') }}</el-button> -->
                            <!--资产调拨-->
                            <!-- <el-button size="gv" icon="fa fa-exchange"
                                         :loading="loading" @click="editMenu()"
                                        >{{ $t('AssetIssuance.btnText.assetAllocation') }}</el-button> -->
                            <!--下发-->
                            <el-button size="gv" icon="el-icon-delete"
                                v-permission="{menuCode: menuCode, resourceCode: 'sendSubBtnText'}"
                                type="danger" :loading="loading" @click="onSend(scope.$index, scope.row,'sendSubBtnText')" :disabled="scope.row.sendtoState!='StayDown' || curRootAssets.sendtoStateFlag!='DownAlready' || scope.row.distribute!=null"
                                >{{ $t('AssetIssuance.btnText.Issued') }}</el-button>
                            <!--注入-->
                            <el-button size="gv" icon="el-icon-delete"
                                v-permission="{menuCode: menuCode, resourceCode: 'sendSubBtnText'}"
                                type="danger" :loading="loading" @click="onSendCDN(scope.$index, scope.row,'sendSubBtnText')" :disabled="scope.row.sendtoState!='StayDown'"
                                >{{ $t('AssetIssuance.btnText.sendCDN') }}</el-button>
                        </template>
                    </el-table-column>
                    <!--剧集编号-->
                    <el-table-column prop="subassetCode" min-width="150" fixed="left"
                                        :label="$t('AssetIssuance.table.shellAssets.subAssetCode')" sortable="custom" sort-by="subassetCode">
                    </el-table-column>
                    <!--剧集名称-->
                    <el-table-column prop="subassetName" min-width="180" fixed="left"
                                        :label="$t('AssetIssuance.table.shellAssets.subAssetName')" sortable="custom" sort-by="subassetName">
                    </el-table-column>
                    <!-- 剧集数 -->
                    <el-table-column prop="subassetNum" min-width="110"
                        :label="$t('AssetIssuance.table.shellAssets.itemNum')" sortable="custom" sort-by="subassetNum">
                    </el-table-column>
                    <!--资产来源-->
                    <!-- sortable="custom" sort-by="assetEntity.assetSpeArea.speAreaName" -->
                    <el-table-column prop="speAreaName" min-width="110"
                                        :label="$t('AssetIssuance.table.shellAssets.source')" >
                    </el-table-column>
                    <!--资产类型-->
                    <el-table-column prop="assetType" min-width="110" sortable="custom" sort-by="assetType"
                                        :label="$t('AssetIssuance.table.shellAssets.type')" >
                    </el-table-column>
                    <!--剧集状态-->
                    <el-table-column prop="approvalStatus" min-width="110" sortable="custom" sort-by="approvalStatus"
                                        :label="$t('AssetIssuance.table.shellAssets.subAssetStatus')" >
                    </el-table-column>
                    <!--下发状态-->
                    <el-table-column prop="sendtoStateName" min-width="110"
                                        :label="$t('AssetIssuance.table.shellAssets.turndownStatus')" sortable="custom" sort-by="sendtoState">
                    </el-table-column>
                    <!--授权时间
                    <el-table-column prop="expireTime" min-width="120"
                                        :label="$t('shellAssets.table.shellAssets.expireTime')" sortable="custom" sort-by="expireTime">
                    </el-table-column>
                    -->
                    <!--版权结束时间-->
                    <el-table-column prop="copyrightEndDate" min-width="180"
                                        :label="$t('AssetIssuance.table.shellAssets.expireEndTime')" sortable="custom" sort-by="copyrightEndDate">
                    </el-table-column>
                    <!--创建时间-->
                    <el-table-column prop="createdDate" min-width="180"
                                        :label="$t('AssetIssuance.table.shellAssets.createTime')" sortable="custom" sort-by="createdDate">
                    </el-table-column>
                    <!--最后修改时间-->
                    <el-table-column :label="$t('AssetIssuance.table.lastUpdateTime')" min-width="180" sortable="custom" prop="lastUpdatedDate" sort-by="lastUpdatedDate">
                    </el-table-column>
                    <!--最后修改人-->
                    <el-table-column :label="$t('AssetIssuance.table.lastUpdatedBy')" min-width="180" sortable="custom" prop="modifier" sort-by="modifier">
                    </el-table-column>
                </el-table>


            </div>
        </div>
        <!--分页-->
        <div class="pageBox">
            <el-pagination @size-change="sizeChange"
                            @current-change="currentPageChange"
                            :current-page="pager.curPage"
                            :page-sizes="pager.sizes"
                            :page-size="pager.curSize"
                            :background="true"
                            layout="total, sizes, prev, pager, next, jumper" :total="pager.total">
            </el-pagination>
        </div>

        <!-- 注入选择站点对话框 -->
        <transition enter-active-class="animated rotateIn" leave-active-class="animated rotateOut">
        <el-dialog :title="$t('AssetIssuance.label.launchDialogTitle')" :visible.sync="isShowEditForm2" top="5vh" @close="refresh" :close-on-click-modal="false">
            <el-form :inline="true" :model="sendForm" ref="sendForm" size="mini"
                     :label-position="editFormPosition" status-icon=status-icon :rules="sendRules">

            <el-row>
              <el-form-item :label="$t('')" :label-width="editformLabelWidth" prop="siteList">


                <el-radio-group v-model="sendForm.siteList">
                        <el-radio :value="item.siteName" :key="item.keyId" :label="item.keyId" v-for="item in siteDataCDN">{{item.siteName}}</el-radio>
                </el-radio-group>
                </el-form-item>
            </el-row>

            </el-form>
            <div slot="footer">
                <el-button size="mini" @click="isShowEditForm2 = false" :loading="loading">{{ $t('btnText.cancelBtnText') }}</el-button>
                <el-button size="mini" type="primary" @click="comfirmSendCDN('sendForm')" :loading="loading">{{ $t('btnText.sendConfirmBtnText') }}</el-button>
            </div>

        </el-dialog>
      </transition>


  </div>


</template>

<script>

import comBaseVue from '../../baseViewModel';
import { close } from 'fs';

export default {
  mixins: [comBaseVue],
  name:'AssetIssuance',
  props: {
    isNeedGoBack: Boolean,
    curRootAssets: null,
    menuCode: String,
  },
  data () {

    return {
        isShowActor:  false,
        isShowDetails:false,
        isShowEditForm2: false,
        isShowRecycle: false,
        activeName: 'first',
        lookName: 'look',
        isInit:false,
        tableHeight:100,
        multipleSelection: [],
        singleSend: {},
        siteData:[],
        siteDataCDN:[],
        assetData:[],
        assetSourceData:[],
        sendtoStateData:[],
        queryformLabelWidth:"84px",
        appDivStyle:{
            height:this.$store.getters.appHeight,
        },
        modelName:"com.ispr.iptv.entity.media.SubAssetEntity",//操作的实体类

        fileList2: [],
        //
        changeLogData:[],
        // 查询条件
        formQueryCondition: {
            assetCode: {
                key: 'assetId',
                op: '=',
                val: "",
            },
            code: {
                key: 'subassetCode',
                op: 'LIKE', // 操作符
                val: '' // 查询的值
            },
            name: {
                key: 'subassetName',
                op: 'LIKE',
                val: ''
            },
            // director: {
            //     val: ''
            // },
            // actor: {
            //     val: ''
            // },
            source: {
                key: 'assetSource',
                op: '=',
                val: ''
            },
            createTimeStart: {
                key: 'createdDate',
                group: 'createTimeStart',
                op: '>=',
                val: ''
            },
            createTimeEnd: {
                key: 'createdDate',
                group: 'createTimeEnd',
                op: '<=',
                val: ''
            },
            lastUpdateTimeStart: {
                key: 'lastUpdatedDate',
                group: 'lastUpdateTimeStart',
                op: '>=',
                val: ''
            },
            lastUpdateTimeEnd: {
                key: 'lastUpdatedDate',
                group: 'lastUpdateTimeEnd',
                op: '<=',
                val: ''
            },
            approvalStatus: {
                key: 'approvalStatus',
                op: '=',
                val: 'ExaminationPassed'
            },
            status: {
                key: 'sendtoState',
                op: '=',
                val: 'StayDown'
            },
            isEnable: {
                key: 'isEnable', // 操作符
                op: '=', // 操作符
                val: 'Available' // 查询的值
            },
            // approvalStatus: {
            //     key: 'approvalStatus',
            //     op: '=',
            //     val: 'ExaminationPassed'
            // },

        },

        // 编辑面板绑定的对象
        editForm: {
            keyID: 0,
            version: 0,
            name: "",
            type: "",
            source: "",
            userStatus: "",
            boxType: "",
            operator: "",

            tname: "",
            type: "",
            ource: "",
            sourceInfo: "",
            expireTime: "",
            expireEndTime: "",
            classification: "",
            initials: "",
            years: "",
            area: "",
            language: "",
            episode: "",
            director: "",
            edit: "",
            actor: "",
            playStatus: "",
            boxOffice: "",
            score: "",
            introduction: "",
            plot: "",
            poster: "",
        },
        // 编辑面板的验证规则
        editRules: {
            name: [{ required: true, message: this.$i18n.t('shellAssets.label.placeholder')+this.$i18n.t('shellAssets.editLabel.shellAssets.name'), trigger: 'blur' }],
        },
        sendRules: {
            siteList: [{ required: true, message: this.$i18n.t('ParentAssetIssuance.rules.sendCheckTip'), trigger: 'blur' }],
        },
        //下发
        sendForm: {
            siteList: "",//下发到的站点
            sendType:"",
        },
        // 排序对象
        sort: {
            key: "subassetNum",
            dir: "Desc"
        }
    }
  },
  methods:{
     // 查询按钮
    onQuery: function(rescode) {
        this.currentResCode = (rescode && rescode!=='') ? rescode : '';
        if(this.formQueryCondition.createTimeStart.val!=null
        && this.formQueryCondition.createTimeStart.val!=""){
            this.formQueryCondition.createTimeStart.val=this.formatDate(this.formQueryCondition.createTimeStart.val);
        }
        if(this.formQueryCondition.createTimeEnd.val!=null
        && this.formQueryCondition.createTimeEnd.val!=""){
            this.formQueryCondition.createTimeEnd.val=this.formatDate(this.formQueryCondition.createTimeEnd.val);
        }
        if(this.formQueryCondition.lastUpdateTimeStart.val!=null
        && this.formQueryCondition.lastUpdateTimeStart.val!=""){
            this.formQueryCondition.lastUpdateTimeStart.val=this.formatDate(this.formQueryCondition.lastUpdateTimeStart.val);
        }
        if(this.formQueryCondition.lastUpdateTimeEnd.val!=null
        && this.formQueryCondition.lastUpdateTimeEnd.val!=""){
            this.formQueryCondition.lastUpdateTimeEnd.val=this.formatDate(this.formQueryCondition.lastUpdateTimeEnd.val);
        }
        this.pager.curPage = 1;
        this.queryTable();
    },

     // 查询网格数据
    queryTable: function() {
        this.loading = true;
        this.auditConfirmQuery("/api/subAsset/selectPage",this.modelName,"Query",this.formQueryCondition,this.pager,this.sort,this.setTableData)
    },

     // 网格数据成功后的回调
    // setTableData: function(isSuccess,json) {
    //     this.loading = false;
    //     // console.log(json);
    //     try{
    //         if (isSuccess) {
    //             //alert(JSON.stringify(json));
    //             this.pager.total = json.total;
    //             this.curRootAssets = [];
    //             for (var i = 0; i < json.list.length; i++) {
    //                 this.curRootAssets.push(json.list[i]);
    //             }

    //         }
    //         else {
    //             this.$message.error(this.$i18n.t("errorCode." + json.reason,json.message));
    //         }
    //     }
    //     catch(e){
    //         alert(e);
    //     }
    // },
     // 重置
    onReset:function(){
        if (this.$refs['form']) {
            this.$refs['form'].resetFields();
        }
        this.formQueryCondition.code.val = "";
        this.formQueryCondition.name.val = "";
        // this.formQueryCondition.director.val = "";
        // this.formQueryCondition.actor.val = "";
        this.formQueryCondition.source.val = "";
        this.formQueryCondition.approvalStatus.val = "ExaminationPassed";
        this.formQueryCondition.status.val = "";
        this.formQueryCondition.createTimeStart.val = "";
        this.formQueryCondition.createTimeEnd.val = "";
        this.formQueryCondition.lastUpdateTimeStart.val = "";
        this.formQueryCondition.lastUpdateTimeEnd.val = "";
    },
    //回退事件
    back: function(isSuccess, json) {
        //this.$router.go(-1);//后退
        this.$parent.setCurrentComponent("goBack",null);
    },
    //剧集单个下发
    // onSend: function(index, row,rescode) {
    //     this.currentResCode = (rescode && rescode!=='') ? rescode : '';
    //     this.sendForm.sendType = "single";
    //     this.singleSend = {};
    //     let keyId = row.keyId;
    //     let assetId = row.assetId;
    //     let version = row.version;
    //     let sendtoState = "DownAlready";
    //     var data = {"keyId":keyId,"assetId":assetId,"version":version,"sendtoState":sendtoState};
    //     this.singleSend = data;
    //     this.isShowEditForm2 = true;
    // },

    //剧集单个注入
    onSendCDN: function(index, row, rescode) {
        this.currentResCode = (rescode && rescode!=='') ? rescode : '';
        this.sendForm.sendType = "single";
        this.singleSend = {};
        let keyId = row.keyId;
        let version = row.version;
        let sendtoState = "DownAlready";
        let data = {"keyId":keyId,"version":version,"sendtoState":sendtoState};
        this.singleSend = data;
        this.isShowEditForm2 = true;
    },

    // 提交注入界面数据
    comfirmSendCDN: function (formName, rescode){
        this.currentResCode = (rescode && rescode!=='') ? rescode : '';
        var _this = this;
        this.singleSend.siteId = this.sendForm.siteList;
        this.$refs[formName].validate(function (valid) {
            if (valid) {
                _this.loading = true;
                _this.procCommand("MediaToCdnNewProc",
                _this.modelName,
                "Default",
                _this.singleSend,
                null,
                _this.comfirmSendCallback);
            } else {
                return false;
            }
        });
    },

    //单个下发
    onSend: function(index, row, rescode) {
        var _this = this;
        this.currentResCode = (rescode && rescode!=='') ? rescode : '';
        this.sendType = "single";
        this.singleSend = {};
        let dataList = [];//最终传给后台的总数据
        let data2 = {
          "keyId":row.keyId,
          "assetId":row.assetId,
          "version":row.version,
          "sendtoState":"DownAlready",
        };
        this.singleSend = data2;
        let siteListJson = [];//站点的数据
        for (let i=0;i<this.assetData.length;i++){
            let siteId = this.assetData[i];
            let resType = "J";
            let state = "Untreated";
            let data = {"siteId":siteId,"resType":resType,"state":state};
            siteListJson.push(data);
        };
        this.singleSend.siteList = siteListJson;
        dataList.push(this.singleSend);
        this.$confirm(this.$i18n.t("message.confirmSendMessage"),
            this.$i18n.t("message.confirmTitle"), {
            confirmButtonText: this.$i18n.t("message.yes"),
            cancelButtonText: this.$i18n.t("message.cancel"),
            type: "warning",
            callback: function (action, instance) {
                if (action == "confirm") {
                    _this.loading = true;
                    _this.procCommand("MediaSendToProc",
                    _this.modelName,
                    "Default",
                    {
                      "assetId":_this.curRootAssets.assetId,
                      "dataList":dataList,
                    },
                    null,
                    _this.submitFormCallback);
                }
            }
        });
    },

    //批量下发
    onBatchSend: function(rescode) {
        this.currentResCode = (rescode && rescode!=='') ? rescode : '';
        if(this.multipleSelection.length==0){
            this.$message({
                message: this.$i18n.t("AssetIssuance.label.checkTip"),
                type: 'warning'
            });
            return;
        }
        var _this = this;
        let dataList = [];//最终传给后台的总数据
        let siteListJson = [];//站点的数据
        for (let i=0;i<this.assetData.length;i++){//装站点
            let siteId = this.assetData[i];
            let resType = "J";
            let state = "Untreated";
            let data = {"siteId":siteId,"resType":resType,"state":state};
            siteListJson.push(data);
        };
        for(let i=0;i<this.multipleSelection.length;i++){//装数据
            let temp = this.multipleSelection[i];
            temp.siteList = siteListJson;
            dataList.push(temp);
        }
        this.$confirm(this.$i18n.t("message.confirmSendMessage"),
            this.$i18n.t("message.confirmTitle"), {
            confirmButtonText: this.$i18n.t("message.yes"),
            cancelButtonText: this.$i18n.t("message.cancel"),
            type: "warning",
            callback: function (action, instance) {
                if (action == "confirm") {
                    _this.loading = true;
                    _this.procCommand("MediaSendToProc",
                    _this.modelName,
                    "Default",
                    {
                        "assetId":_this.curRootAssets.assetId,
                        "dataList":dataList,
                    },
                    null,
                    _this.comfirmSendCallback);
                }
            }
        });
    },

    // //批量下发
    // onBatchSend: function(rescode) {
    //     this.currentResCode = (rescode && rescode!=='') ? rescode : '';
    //     if(this.multipleSelection.length==0){
    //         this.$message({
    //             message: this.$i18n.t("AssetIssuance.label.checkTip"),
    //             type: 'warning'
    //         });
    //         return;
    //     }
    //     this.sendForm.sendType = "batch";
    //     this.isShowEditForm2 = true;
    // },
    changeBox: function(val) {
        this.multipleSelection = [];
        for (let i=0;i<val.length;i++){
            let keyId = val[i].keyId;
            let assetId = val[i].assetId;
            let version = val[i].version;
            let sendtoState = "DownAlready";
            let data = {"keyId":keyId,"assetId":assetId,"version":version,"sendtoState":sendtoState};
            this.multipleSelection.push(data);
        }
    },
    refresh: function(){
        if (this.$refs['sendForm']) {
            this.$refs['sendForm'].resetFields();
        }
        this.sendForm.siteList = [];
    },
    checkboxInit: function(row,index){
        if (row.sendtoState == 'StayDown' && this.curRootAssets.sendtoStateFlag=='DownAlready') {
            return true;
        }else{
            return false;
        }
    },
     // 提交编辑面板数据
    comfirmSend: function (formName) {
        var _this = this;
        let dataList = [];//最终传给后台的总数据
        let siteListJson = [];//站点的数据
        for (let i=0;i<this.sendForm.siteList.length;i++){
            let siteId = this.sendForm.siteList[i];
            let resType = "J";
            let state = "Untreated";
            let data = {"siteId":siteId,"resType":resType,"state":state};
            siteListJson.push(data);
        };
        if(this.sendForm.sendType=="batch"){
            for(let i=0;i<this.multipleSelection.length;i++){
                let temp = this.multipleSelection[i];
                temp.siteList = siteListJson;
                dataList.push(temp);
            }
        }else if(this.sendForm.sendType=="single"){
            this.singleSend.siteList = siteListJson;
            dataList.push(this.singleSend);
        }
        this.$refs[formName].validate(function (valid) {
            if (valid) {
                _this.loading = true;
                _this.procCommand("MediaSendToProc",
                _this.modelName,
                "Default",
                {
                    "assetId":_this.curRootAssets.assetId,
                    "dataList":dataList,
                },
                null,
                _this.comfirmSendCallback);
            } else {
                return false;
            }
        });
    },
    // 执行命令后的回调函数
    comfirmSendCallback: function (isSuccess,json) {
        this.loading = false;
        if(isSuccess){
            this.isShowEditForm2 = false;
            this.$message({
                message: this.$i18n.t("message.successTip"),//resource.message.successTip,
                type: 'success'
            });
            this.queryTable();
        }
        else
        {
            this.$message.error(json.msg);
            // this.$message({
            //                 message: this.$i18n.t("errorCode." + json.reason),
            //                 type: 'warning'
            //                 });
        }
    },

     //资产来源下拉列表数据
    // findAssetSource: function(){
    //     this.findByTypeCode("10008",this.setAssetSourceCallback);
    // },

    findAssetSource: function(){
        var queryRequest = {
                className: "com.ispr.iptv.entity.sys.SpeArea",//修改为被查询的实体地址
                opKey: "Query",//后台编写相应的接口实现方法，主要负责转化类型
                params: [{key: 'isEnable',op: '=',val: 'Available'}],
                userInfo: this.getUserInfo()
            };
            var _this = this;
            this.axios.post('/api/query', queryRequest, {headers: this.headersObj})
                .then(function(res) {
                    // alert(JSON.stringify(res));
                    // alert(res.data.code);
                    if (res.data.code == "SUCCESS") {
                        _this.assetSourceData = [];
                        for (var i = 0; i < res.data.data.length; i++) {
                            _this.assetSourceData.push(res.data.data[i]);
                        }
                    } else {
                        // this.$message.error(this.$i18n.t("errorCode." + json.reason,json.message));
                    }
                })
                .catch(function(error) {
                    console.log(error);
                    // this.$message.error(this.$i18n.t("errorCode." + json.reason,json.message));
                });
    },

    // setAssetSourceCallback: function(isSuccess,json){
    //     try{
    //         if (isSuccess) {
    //             for (var i = 0; i < json.data.length; i++) {
    //                 this.assetSourceData.push(json.data[i]);
    //             }
    //         }
    //         else {
    //             this.$message.error(this.$i18n.t("errorCode." + json.reason,json.message));
    //         }
    //     }
    //     catch(e){
    //         alert(e);
    //     }
    // },

    //下发状态下拉列表数据
    findSendtoState: function(){
        this.findByTypeCode("10011",this.setSendtoStateCallback);
    },

    setSendtoStateCallback: function(isSuccess,json){
        try{
            if (isSuccess) {
                for (var i = 0; i < json.data.length; i++) {
                    this.sendtoStateData.push(json.data[i]);
                }
            }
            else {
                this.$message.error(json.msg);
            }
        }
        catch(e){
            alert(e);
        }
    },
     //根据ID查询站点数据
    findAsset: function(){

        var queryRequest = {
                className: "com.ispr.iptv.entity.media.AssetEntity",//修改为被查询的实体地址
                opKey: "Query",//后台编写相应的接口实现方法，主要负责转化类型
                params: [{key: 'keyId',op: '=',val: this.curRootAssets.assetId},{key: 'isEnable',op: '=',val: 'Available'}],
                userInfo: this.getUserInfo()
            };
            var _this = this;
            this.axios.post('/api/query', queryRequest, {headers: this.headersObj})
                .then(function(res) {
                    // alert(JSON.stringify(res));
                    // alert(res.data.code);

                    if (res.data.code == "SUCCESS") {
                        _this.assetData = [];
                        // _this.$nextTick(function () {
                        for (var i = 0; i < res.data.data.length; i++) {
                            let siteId = res.data.data[i].sendSiteId.split(',');
                                _this.assetData=siteId;
                        }
                        // });

                    } else {
                        // this.$message.error(this.$i18n.t("errorCode." + json.reason,json.message));
                    }
                })
                .catch(function(error) {
                    console.log(error);
                    // this.$message.error(this.$i18n.t("errorCode." + json.reason,json.message));
                });
    },

     //站点复选框数据 siteData
    findSite: function(){
        var queryRequest = {
                className: "com.ispr.iptv.entity.sys.Site",//修改为被查询的实体地址
                opKey: "Query",//后台编写相应的接口实现方法，主要负责转化类型
                params: [{key: 'isEnable',op: '=',val: 'Available'}],
                userInfo: this.getUserInfo()
            };
            var _this = this;
            this.axios.post('/api/query', queryRequest, {headers: this.headersObj})
                .then(function(res) {
                    // alert(JSON.stringify(res));
                    // alert(res.data.code);
                    if(_this.curRootAssets.sendSiteId!=null){
                        let siteId = _this.curRootAssets.sendSiteId.split(',');
                            _this.assetData=siteId;
                    }

                    if (res.data.code == "SUCCESS") {
                        _this.siteData = [];
                        _this.siteDataCDN = [];
                        for (var i = 0; i < res.data.data.length; i++) {
                            _this.siteDataCDN.push(res.data.data[i]);
                            for (var n = 0;n<_this.assetData.length; n++) {
                                if(_this.assetData[n] === res.data.data[i].keyId){
                                    _this.siteData.push(res.data.data[i]);
                                }
                            }
                        }
                    } else {
                        // this.$message.error(this.$i18n.t("errorCode." + json.reason,json.message));
                    }
                })
                .catch(function(error) {
                    console.log(error);
                    // this.$message.error(this.$i18n.t("errorCode." + json.reason,json.message));
                });
    },

    initTable:function(){
        //alert("setTimeout");
        this.tableHeight = this.$refs.context.offsetHeight - this.$refs.queryBox.offsetHeight;
        this.isInit = true;
    },
    enterDown(){
      var g = this
      if(g.isShowEditForm2){
          g.comfirmSend('sendForm')
      }else if(!g.loading){
          g.onQuery()
      }
    }

  },
  activated: function() {
     this.formQueryCondition.assetCode.val = this.curRootAssets.assetId;
     //this.findAsset();
     this.findSite();
     this.onQuery();
  },
  mounted: function mounted() {
    //   console.log('this.curRootAssets.assetId===========>',this.curRootAssets.assetId)
    //this.findAsset();
    this.findSite();
    this.findAssetSource();
    this.findSendtoState();
    //this.onQuery();
    window.setTimeout(this.initTable,100);
  },
}


</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
